package com.zjx.springcloud.utils;



import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.ResourceBundle;

public class LanguageUtils {

    //设置语言环境
    public  static final int  CN = 1;//中文
    public  static final int  US =2;//英文

    /**
     * @param  local  国际话  1 中文  2英文
     * @param key 国际化的key
     * @return  返回中文，英文文字
     */
    public  static String getText(int local, String key) {
        ResourceBundle myResources=null;
         switch (local){
             case 1:
                 myResources= ResourceBundle.getBundle("language_zh",Locale.CHINA);//加载myproperties_zh.properties
                 break;
             case 2:
                 myResources = ResourceBundle.getBundle("language_zh",Locale.US);//加载myproperties_zh.properties

                 break;
             default:
                 return "";
         }

        return new String(myResources.getString(key).getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
    }

    /**
     * @param key 国际化的key
     * @return  返回中文文字
     */
    public  static String getDefaultText( String key) {
        ResourceBundle myResources=null;
        myResources= ResourceBundle.getBundle("language_zh",Locale.CHINA);//加载myproperties_zh.properties

        return new String(myResources.getString(key).getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
    }
}
